/*
 * @Autor: Ruohong Yu
 * @Date: 2022-09-02 17:33:00
 * @Description: file content
 * @FilePath: \ebook\src\lang\index.js
 */
import { createI18n } from 'vue-i18n'
import en from './en'
import cn from './cn'
import { getLocale, saveLocale } from '../utils/localStorage'

const messages = {
  en, cn
}
let locale_ = getLocale()

const localeData = {
  legacy: false, // composition API
  globalInjection: true,
  locale: locale_,
  messages
}

export function setupI18n (app) {
  if (!locale_) {
    locale_ = 'cn'
    saveLocale(locale_)
  }
  const i18n = createI18n(localeData)
  app.use(i18n)
}
